//
//  GQHAboutController.m
//  Xanthium
//
//  Created by GuanQinghao on 02/03/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#pragma mark Macro
#import "GQHHeader.h"

#pragma mark Model

#pragma mark Object

#pragma mark View

#pragma mark Controller
#import "GQHAboutController.h"
#import "GQHBaseModel.h"

#pragma mark CocoaPods

#pragma mark ----------Header End----------

@interface GQHAboutController ()  <UITextViewDelegate>{
    
#pragma mark Data
    UITextView * textView;
    UIWebView * webView;
#pragma mark View
    
}

@end


@implementation GQHAboutController

#pragma mark --Lifecycle
- (void)viewDidLoad {
    [super viewDidLoad];
    DLog();
    
    [self loadUserInterface];
//    [self loadData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    DLog();
    
    self.qh_titleLabel.text = @"关于我们";
    self.qh_rightButton.hidden = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    DLog();
    
}

#pragma mark --Delegate

#pragma mark --TargetMethod

#pragma mark --PrivateMethod

#pragma mark --Setter

#pragma mark --Getter

#pragma mark --View
- (void)loadUserInterface {
    
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGFloat height = [UIScreen mainScreen].bounds.size.height;
    
//    UIImageView *logoImageView = [[UIImageView alloc] init];
//
//    logoImageView.image = [UIImage imageNamed:@"basic_logo"];
//    logoImageView.frame = CGRectMake(width / 2 - 30, self.view.qh_navigationBarHeight + self.view.qh_statusBarHeight + 60, 60, 60);
//    logoImageView.layer.cornerRadius = 10.0;
//    logoImageView.layer.masksToBounds = YES;
//    [self.view addSubview:logoImageView];
//
//    UILabel *captionLabel = [[UILabel alloc] init];
//    captionLabel.frame = CGRectMake(0, CGRectGetMaxY(logoImageView.frame), width, 40);
//    captionLabel.font = kBiggerFont;
//    captionLabel.text = @"云交智运";
//    captionLabel.textColor = kBlackColor;
//    captionLabel.textAlignment = NSTextAlignmentCenter;
//    [self.view addSubview:captionLabel];
//
//    UILabel *versionLabel = [[UILabel alloc] init];
//    versionLabel.frame = CGRectMake(0, CGRectGetMaxY(captionLabel.frame), width, 40);
//    versionLabel.font = kDefaultFont;
//    versionLabel.text = @"v1.0.0 build 1 for iPhone(iOS9.0 later)";
//    versionLabel.textColor = kDarkGrayColor;
//    versionLabel.textAlignment = NSTextAlignmentCenter;
//    [self.view addSubview:versionLabel];
//
//    UILabel *copyrightLabel = [[UILabel alloc] init];
//    copyrightLabel.frame = CGRectMake(0, height - self.view.qh_homeIndicatorHeight - 60, width, 60);
//    copyrightLabel.font = kSmallerFont;
//    copyrightLabel.text = @"Copyright ©2018 云交智运 All Rights Reserved";
//    copyrightLabel.textColor = kDarkGrayColor;
//    copyrightLabel.textAlignment = NSTextAlignmentCenter;
//    [self.view addSubview:copyrightLabel];

    CGFloat scrollView_y = self.view.qh_navigationBarHeight + self.view.qh_statusBarHeight;
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, scrollView_y, width, height - self.view.qh_homeIndicatorHeight - scrollView_y)];
    webView.dataDetectorTypes = UIDataDetectorTypeAll;
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[[NSString qh_APIURLString] stringByAppendingPathComponent:@"buLargeTextEditor/1/list?largerType=04"]]]];
    [self.view addSubview:webView];
}


- (void)loadData
{
    [GQHNetHelper qh_requestGET:[[NSString qh_APIURLString] stringByAppendingPathComponent:@"buLargeTextEditor/1/list?largerType=04"] parameters:@{} success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        
        if (code.intValue == 0)
        {
            NSString * string = data[@"list"][0][@"content"];
            
//            NSString *str = [NSString stringWithFormat:@"<head><style>img{width:%f !important;height:auto}</style></head>%@",self.view.qh_width - 30,string];
//            //富文本，两种都可以
//            NSDictionary *options = @{ NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute :@(NSUTF8StringEncoding) };
//            NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
//            //或者
//            //    NSDictionary *option = @{NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType};
//            //    NSData *data = [htmlStr dataUsingEncoding:NSUnicodeStringEncoding];
//
//            //设置富文本
//            NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithData:data options:options documentAttributes:nil error:nil];
//            //设置段落格式
//            NSMutableParagraphStyle *para = [[NSMutableParagraphStyle alloc] init];
//            para.lineSpacing = 7;
//            para.paragraphSpacing = 10;
//            [attStr addAttribute:NSParagraphStyleAttributeName value:para range:NSMakeRange(0, attStr.length)];
//            textView.attributedText = attStr;
//
//            //设置文本的Font没有效果，默认12字号，这个只能服务器端控制吗？ 暂时没有找到方法修改字号
//            [attStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, attStr.length)];
            
            [webView loadHTMLString:string baseURL:nil];
        }
        
    } failure:^(NSError *error) {
        
    }];
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    return NO;
}

@end
